<template>
	<div>
		<div class="box">
			<uni-forms
				ref="form"
				:model="currentInfoData"
				validate-trigger="bind"
				:label-position="state == 'write' ? 'top' : 'left'"
				label-width="auto">
				<FromItem state="readonly" label="APR" name="ARR">
					{{ computedData.APR() }}
				</FromItem>
				<FromItem state="readonly" label="IRR" name="IRR">
					{{ computedData.IRR() }}
				</FromItem>
				<FromItem state="readonly" label="含资金成本IRR" name="IRR">
					{{ computedData.COSTIRR() }}
				</FromItem>
				<FromItem state="readonly" label="月费率" name="IRR">
					{{ computedData.monthRate() }}
				</FromItem>
				<FromItem state="readonly" label="总费率" name="IRR">
					{{ computedData.allRate() }}
				</FromItem>
			</uni-forms>
		</div>
	</div>
</template>

<script>
	import * as app from '@/api/index.js';
	import * as apis from '@/api/quota/apply/api.js';
	import * as utils from '@/pages/quota/libs/utils.js';
	import FromItem from '../formItem/index.vue';
	export default {
		name: '',
		components: { FromItem },
		dicts: [],
		props: {},
		inject: [
			'details_provide',
			'config_provide',
			'deptList_provide',
			'state_provide',
			'index_provide',
			'planDicts_provide',
			'fromtype_provide',
		],
		data() {
			return {};
		},
		computed: {
			details() {
				return this.details_provide();
			},
			config() {
				return this.config_provide();
			},
			deptList() {
				return this.deptList_provide();
			},
			planDicts() {
				return this.planDicts_provide();
			},
			state() {
				return this.state_provide();
			},
			fromtype() {
				return this.fromtype_provide();
			},

			index() {
				return this.index_provide();
			},
			currentInfoData() {
				return this.details.productList?.[this.index] ?? {};
			},
			firstInfoData() {
				return this.details.productList?.[0] ?? {};
			},
			calcSnapshoot: {
				get() {
					if (
						this.currentInfoData.calcSnapshoot &&
						typeof this.currentInfoData.calcSnapshoot == 'string'
					) {
						return (
							JSON.parse(this.currentInfoData.calcSnapshoot) || {}
						);
					} else {
						return this.currentInfoData.calcSnapshoot || {};
					}
				},
			},
			computedData() {
				return {
					APR: () => {
						let row = this.calcSnapshoot;
						let apr = this.notEmpty(row.apr)
							? row.apr
							: row.pricingIrr;
						let price = utils.toNumberRide(apr, 100);
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2)) + '%'
							: '-';
					},
					IRR: () => {
						let row = this.calcSnapshoot;
						let price = utils.toNumberRide(
							row?.cashFlowCalcResult?.irr * 1,
							100,
						);
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2)) + '%'
							: '-';
					},
					COSTIRR: () => {
						let row = this.calcSnapshoot;
						let price = utils.toNumberRide(
							row?.cashFlowCalcResult1?.irr * 1,
							100,
						);
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2)) + '%'
							: '-';
					},
					monthRate: () => {
						let row = this.calcSnapshoot;
						let price = utils.toNumberRide(
							row?.rentCalcResult?.leaseRatePerPeriod * 1,
							100,
						);
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2)) + '%'
							: '-';
					},
					allRate: () => {
						let row = this.calcSnapshoot;
						let price = utils.toNumberRide(
							row?.rentCalcResult?.totalLeaseRate * 1,
							100,
						);
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2)) + '%'
							: '-';
					},
				};
			},
		},
		watch: {},
		filters: {},
		created() {},
		mounted() {},
		methods: {},
	};
</script>

<style lang="scss" scoped>
	.box {
		// margin: 20rpx;
		// padding: 20rpx;
		padding-top: 20rpx;
		background-color: #fff;
		border-radius: 8rpx;
		.title {
			border-bottom: 1px solid #e9e9e9;
			font-weight: 500;
			padding-bottom: 10rpx;
			margin-bottom: 10rpx;
		}
	}
</style>
